<template>
<section class="content" id="content">
  <lq-form :form="form" :rules="rules" ref="addEntBasicInfoFormRef">
  </lq-form>
</section>
</template>

<script setup lang="ts">
/**
 * 全局方法引入
 */
const global = getCurrentInstance().appContext.config.globalProperties;

import {
  ref,
  reactive,
  inject,
  defineExpose,
  getCurrentInstance
} from "vue";
import {FormInstance, FormRules} from "element-plus";

import {ElMessage, ElMessageBox} from "element-plus";
import LqForm from "@/pages/components/LqForm.vue";


// 表单数据结构
const form = ref({
  innerAttrs: {
    labelPosition: 'right',
    labelWidth: 180,
    disabled: false,
  },
  /*model: {
    companyName: '',
    companyCode: '',
    administrativeDivision: '',
    creditCode: '',
    companyType: '',
    businessTypeName: '',
    businessTypeCode: '',
    industryTypeName: '',
    industryTypeCode: '',
    businessRegisterAddress: '',
    businessRegisterTime: '',
    entCoordinate: '',
    firmBoundary: '',
    businessRegisterScope: '',
    employeeCount: '',
    saleIncome: '',
    businessRegisterCapital: '',
    companyScale: '',
    companyHomepage: '',
    mainProducts: '',
    chemicalIndustryTypeName: '',
    isInPark: '',
    area: '',
    warehouseArea: '',
    warehouseVolume: '',
    emergencyPhone: '',
    emergencyDutyPhone: '',
    instrumentationCount: ''
  },*/
  model: {
    "administrativeDivision": "string",
    "archiveDate": "2024-02-24T14:19:57.859Z",
    "archiveNumber": "string",
    "area": 0,
    "auditStatus": "string",
    "businessRegisterAddress": "string",
    "businessRegisterCapital": 0,
    "businessRegisterScope": "string",
    "businessRegisterTime": "2024-02-24T14:19:57.859Z",
    "businessTypeCode": "string",
    "businessTypeName": "string",
    "chemicalIndustryTypeCode": "string",
    "chemicalIndustryTypeName": "string",
    "companyCode": "string",
    "companyHomepage": "string",
    "companyName": "string",
    "companyScale": "string",
    "companyType": "string",
    "createTime": "2024-02-24T14:19:57.859Z",
    "createUser": "string",
    "emergencyDutyPhone": "string",
    "emergencyPhone": "string",
    "emgcySysParkId": "string",
    "employeeCount": 0,
    "id": "string",
    "industryTypeCode": "string",
    "industryTypeName": "string",
    "insertTime": "2024-02-24T14:19:57.859Z",
    "instrumentationCount": 0,
    "isInPark": true,
    "latitude": 0,
    "longitude": 0,
    "mainProducts": "string",
    "orgId": "string",
    "parkId": "string",
    "saleIncome": 0,
    "sort": 0,
    "updateTime": "2024-02-24T14:19:57.859Z",
    "updateUser": "string",
    "warehouseArea": 0,
    "warehouseVolume": 0
  },
  formItems: [
    {type: 'input', label: '企业名称: ', prop: 'companyName', span: 12, maxlength: 30, placeholder: '企业名称'},
    {type: 'input', label: '企业编码: ', prop: 'companyCode', span: 12, maxlength: 30, placeholder: '企业编码'},
    {type: 'input', label: '行政区划: ', prop: 'administrativeDivision', span: 12, placeholder: '行政区划'},
    {type: 'input', label: '统一社会信用代码: ', prop: 'creditCode', span: 12, placeholder: '统一社会信用代码'},
    {type: 'select', label: '企业类型: ', prop: 'companyType', span: 12, options: [{label: '有限责任公司', value: 1},{label: '股份有限公司', value: 2},{label: '个人独资企业', value: 3},{label: '合伙企业', value: 4},{label: '全民所有制企业', value: 5},{label: '集体所有制企业', value: 6},{label: '农民专业合作社', value: 7}], placeholder: '请选择'},
    {type: 'select', label: '经济类型: ', prop: 'businessTypeName', span: 6, options: [{label: '内资企业', value: 1},{label: '港澳台商投资企业', value: 2},{label: '外商投资企业', value: 3},{label: '其他', value: 4}],placeholder: '经济类型'},
    {type: 'select', prop: 'businessTypeCode', span: 4, options: [{label: '国有企业', value: 1},{label: '集体企业', value: 2},{label: '私营企业', value: 3},{label: '联营企业', value: 4},{label: '股份企业', value: 5}], placeholder: '请选择'},
    {type: 'select', label: '行业分类: ', prop: 'industryTypeName', span: 24, options: [{label: '所产权1', value: 1},{label: '所产权2', value: 2}], placeholder: '行业分类'},
    {type: 'input', label: '行业代码: ', prop: 'industryTypeCode', span: 12, maxlength: 30, placeholder: '行业代码'},
    {type: 'input', label: '工商注册地址: ', prop: 'businessRegisterAddress', span: 12, maxlength: 30, placeholder: '工商注册地址'},
    {type: 'input', label: '工商注册时间: ', prop: 'businessRegisterTime', span: 12, maxlength: 30, placeholder: '工商注册时间'},
    {type: 'input', label: '企业坐标: ', prop: 'entCoordinate', span: 12, maxlength: 30, placeholder: '企业坐标'},
    {type: 'input', label: '企业边界: ', prop: 'firmBoundary', span: 24, maxlength: 30, placeholder: '企业边界'},
    {type: 'textarea', label: '工商营业执照经营范围: ', prop: 'businessRegisterScope', span: 24, rows: 5, placeholder: '工商营业执照经营范围'},
    {type: 'input', label: '企业人数: ', prop: 'employeeCount', span: 12, maxlength: 30, placeholder: '企业人数'},
    {type: 'input', label: '上年度销售收入: ', prop: 'saleIncome', span: 12, maxlength: 30, placeholder: '上年度销售收入'},
    {type: 'input', label: '注册资本(万元): ', prop: 'businessRegisterCapital', span: 12, maxlength: 30, placeholder: '注册资本'},
    {type: 'select', label: '企业规模: ',prop: 'companyScale', span: 12, options: [{label: '大型', value: 1},{label: '中型', value: 2},{label: '小型', value: 3},{label: '微型', value: 4}], placeholder: '请选择企业规模'},
    {type: 'input', label: '企业网址: ', prop: 'companyHomepage', span: 24, maxlength: 30, placeholder: '企业网址'},
    {type: 'textarea', label: '主要产品及生产规横: ', prop: 'mainProducts', span: 24, rows: 7, placeholder: '主要产品及生产规横'},
    {type: 'select', label: '化工行业分类: ', prop: 'chemicalIndustryTypeName', span: 12, options: [{label: '所产权1', value: 1},{label: '所产权2', value: 2}], placeholder: '请选择分类'},
    {type: 'select', label: '企业是否在化工园区: ', prop: 'isInPark', span: 12, options: [{label: '是', value: 1},{label: '否', value: 2}], placeholder: '是否在化工园区'},
    {type: 'input', label: '企业建筑面积: ', prop: 'area', span: 12, maxlength: 30, placeholder: '企业建筑面积'},
    {type: 'input', label: '危险化学品库房或仓储场所建筑面积(平方米): ', prop: 'warehouseArea', span: 12, maxlength: 30, placeholder: '危险化学品库房或仓储场所建筑面积(平方米)'},
    {type: 'input', label: '储罐和容器总容积(立方米): ', prop: 'warehouseVolume', span: 12, maxlength: 30, placeholder: '储罐和容器总容积(立方米)'},
    {type: 'input', label: '应急咨询服务电话: ', prop: 'emergencyPhone', span: 12, maxlength: 30, placeholder: '应急咨询服务电话'},
    {type: 'input', label: '安全值班电话: ', prop: 'emergencyDutyPhone', span: 12, maxlength: 30, placeholder: '安全值班电话'},
    {type: 'input', label: '全厂可燃和有毒有害气体监测仪数量: ', prop: 'instrumentationCount', span: 12, maxlength: 30, placeholder: '全厂可燃和有毒有害气体监测仪数量'},
  ],
  buttonsAttrs: {
    align: 'left'
  }
});

// 表单验证规则
const rules = reactive<FormRules>({
  companyName: [{ required: true, message: '请输入企业名称', trigger: 'blur'}],
  companyCode: [{ required: true, message: '请输入企业编码', trigger: 'blur'}],
  administrativeDivision: [{ required: true, message: '所在行政区域', trigger: 'blur'}],
  creditCode: [{ required: true, message: '请输入统一企业信用代码', trigger: 'blur'}],
});

// 表单验证规则
const addEntBasicInfoFormRef = ref<FormInstance>();

const handleSubmit = async () => {
  const valid = await addEntBasicInfoFormRef.value?.validateForm();
  console.log("测试添加企业基本信息：",valid); //true or false
  if (valid) {
    console.log('执行新增操作！');
    global.$api.insertBasicInfo(Object.assign({}, form.value.model)).then(({ data }) => {
      if (data.status === 'OK') {
        ElMessage({type: "success", message: "您已经成功增加企业基本信息！", duration: 4000});
      }
    });
  }
}

const handleReset = () => {
  addEntBasicInfoFormRef.value?.resetFields();
}

defineExpose({
  handleSubmit,
  handleReset
})

</script>

<style scoped>
.el-select{
  white-space: nowrap;
  overflow: hidden;
}
</style>
